<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s"  uri="/struts-tags" %>
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
   	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="chrome=1">
	<title>管理</title>
    <link href="<%=request.getContextPath()%>/css/bootstrap.css" rel="stylesheet" type="text/css">
    <script src="<%=request.getContextPath()%>/js/jquery-2.0.3.min.js" type="text/javascript"></script>
    <script src="<%=request.getContextPath()%>/js/bootstrap.js" type="text/javascript"></script>  
    <script src="<%=request.getContextPath()%>/js/jquery.twbsPagination.js" type="text/javascript"></script>   
    <script type="text/javascript">
    var menus="${menus}";
    
    $(document).ready(function () {
	    $('#pagination-demo').twbsPagination({	    	
	        totalPages: ${pageCount},
	        visiblePages: ${pageCount}>10?10:${pageCount},
			startPage:${page},
	        version: '1.1',
	        first: "首页",
	        last: "未页",
	        prev: '上一页',
	        next: '下一页',
	        onPageClick: function (event, page) {	        	
	        	if(page!=${page}){
	        		var href;
	        		//判断是子菜单还是主菜单
	        		if(menus=="mainMenus"){
	        			document.getElementById("defaultForm").action="<%=request.getContextPath()%>/Mmenu/Mmenu_listByPage.action?params=0&page="+ page +"&rows=10";
	        		}
	        		if(menus=="subMenus"){
						document.getElementById("defaultForm").action="<%=request.getContextPath()%>/Mmenu/Mmenu_listByPage.action?params=1&page="+ page +"&rows=10";
	        		}
	        		document.getElementById("defaultForm").submit();
	        	}	        	
	        }
	    });

    });
    
    function dele(id)
    {
    	var r=confirm("是否删除？");
    	if(r)
   		{	
    		if(menus=="mainMenus"){
    			location.href="Mmenu/Mmenu_remove.action?params=0&page="+${page}+"&id="+id;
    		}
    		if(menus=="subMenus"){
    			location.href="Mmenu/Mmenu_remove.action?params=1&page="+${page}+"&id="+id;
    		}
   			
   		}
    	
    }
    </script>
</head>

<body>
<div class="panel panel-primary">
  <div class="panel-heading">菜单管理</div>
  <div class="panel-body"> 
  
 <!--  查看主菜单开始    -->
<c:if test="${menus=='mainMenus'}">
  <form class="form-horizontal" id="defaultForm" action="Mmenu_listByPage.action?params=0" method="post">
  	
  	<table>
  		<tr>
  			<td><input type="text" name="t1.text" class="form-control" id="text" placeholder="请输入主菜单名称" style="width: 150px"  value="${t1.text}"></td>
  			<td><button type="submit" class="btn btn-default">查询</button></td>
  			<td><button type="button" onclick="location.href='<%=request.getContextPath()%>/Mmenu/Mmenu_toAdd?menus=mainMenus'" class="btn btn-default">增加</button></td>
  			 		
  		</tr>
  	</table>
  	
  </form>
</c:if>
 <!--  查看主菜单结束   -->
 
 
<c:if test="${menus=='subMenus'}">
  <form class="form-horizontal" id="defaultForm" action="Mmenu_listByPage.action?params=1" method="post">
  	
  	<table>
  		<tr>
  			<td><input type="text" name="t1.text" class="form-control" id="text" placeholder="请输入子菜单名称" style="width: 150px"  value="${t1.text}"></td>
  			<td><button type="submit" class="btn btn-default">查询</button></td>
  			<td><button type="button" onclick="location.href='<%=request.getContextPath()%>/Mmenu/Mmenu_toAdd?menus=subMenus'" class="btn btn-default">增加</button></td>
  			 		
  		</tr>
  	</table>
  	
  </form>
</c:if>

 
  </div>
		<table class="table table-bordered table-hover">
		    <thead>
			    <tr>
					 <th>菜单名称</th>
					 <th>菜单英文名称</th>
					 <c:if test="${menus=='subMenus'}">
					    <th>url</th>
					 </c:if>
			        <th>操作</th>
			    </tr>
		    </thead>
		    <s:iterator value="#list">
			    <tr>
					 <th>${text}</th>
					 <th>${menuNameen}</th>
					 <c:if test="${menus=='subMenus'}">
					    <th>${href}</th>
					 </c:if>
			        <th>
			            <c:if test="${menus=='subMenus'}">
			                <a class="btn btn-primary btn-sm" href="Mmenu_getSubMenu.action?params=${menus }&page=${page }&id=${id }" role="button" >修改</a>
				        </c:if>
				        <c:if test="${menus!='subMenus'}">
				            <a class="btn btn-primary btn-sm" href="Mmenu_get.action?params=${menus }&page=${page }&id=${id }" role="button" >修改</a>
				        </c:if>
				        <a class="btn btn-primary btn-sm" onclick="dele(${id })" href="#" role="button" >删除</a>
			        </th>
			    </tr>        
		    </s:iterator>
		</table>
</div>


		<section id="main-content">
		    <p>
		        <div class="text-center" display="inline">
		            <ul id="pagination-demo" class="pagination-sm">&nbsp;&nbsp;&nbsp;共${pageCount}页</ul>
		        </div>
		    </p>
		</section>



</body>
</html>
